<template>
    <div class="category_list">
        <el-table
                :data="categorys"
                style="width: 100%">
            <el-table-column
                    prop="name"
                    label="名称"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="descript"
                    label="描述"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="count"
                    label="总数">
            </el-table-column>
        </el-table>
        <el-pagination
                background
                layout="prev, pager, next"
                :total="total"
                :page-size="page_size"
                @current-change="handleCurrentChange">
        </el-pagination>
    </div>
</template>

<script>
    import {log,buildParams} from '@/assets/js/util.js'
    export default{
        props:['page','bus'],
        name: 'category_list',
        data () {
            return {
                msg: 'category_list',
                name:'',
                total:0,
                page_size:0,
                cur:1,
                categorys:[],
            }
        },
        methods:{
            init:function () {
                var params = []
                if(this.page = 'cates'){
                    params[0] = 'type=1'
                }else{
                    params[0] = 'type=2'
                }
                params[1] = 'name='+this.name
                params[2] = 'page='+this.cur
                var url = server_url+'/api/admin/category/list'+buildParams(params)
                this.$http.jsonp(url, {}, {
                    headers: {},
                    emulateJSON: true
                }).then(function(response) {
                    this.categorys = response.data.data.data
                    this.total = response.data.data.total
                    this.page_size = response.data.data.per_page
                    log(response)
                }, function(response) {
                    log(response)
                });
            },
            handleSearch:function (key) {
                this.name = key
                this.init()
            },
            handleCurrentChange:function (cur) {
                this.cur = cur
                this.init()
            }
        },
        mounted:function () {
            this.init()
            this.bus.$on('sendKey',this.handleSearch)
        },
    }
</script>

<style>
    .category_list{

    }
</style>